﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="KeywordRuleTree.aspx.cs" Inherits="ZLCMS.Web.SystemManage.weixin.Response.KeywordRuleTree" %>
<%@ Register src="/SystemManage/weixin/Material/SetMaterialControl.ascx" tagname="SetMaterialControl" tagprefix="uc1" %>


<div class="pageContent">   
   	<div class="panelBar">
		<ul class="toolBar">           
            <li><a class="icon" href="javascript:void(0)" onclick="navTab.reload();" title="刷新"><span>刷新</span></a></li>
		</ul>
	</div>

    <div class="unitBox" style="float:left; display:block; overflow:auto; width:358px;">
<div class="pageHeader" style="border:1px #B8D0D6 solid">
	<div class="searchBar">
		<table class="searchContent" width="100%">
			<tr>
				<td width="300px"><h3>关键词结构</h3>
				</td>
			</tr>
		</table>
	</div>
</div>
		
        
<div class="pageContent" style="border:1px #B8D0D6 solid;"  layoutH="70">

<div class="pageFormContent" layoutH="128">
<ul class="ztree" id="menu_tree" setting='
{
	view: {
		addHoverDom: addHoverDom,
		removeHoverDom: removeHoverDom,
        showIcon:false,
		selectedMulti: false
	},
    data: {
		key: {
			name: "RuleTitle"
		},
		simpleData: {
			enable: true,
			idKey: "Id",
			pIdKey: "ParentId"
		},
		keep: {
			parent: false,
			leaf: false
		}
	},
	async: {
		enable: true,
		type: "post",
		url: "/SystemManage/weixin/Response/KeywordRuleTree.aspx?op=LoadKeywordRuleTree",
        otherParam: ["temp", new Date().valueOf()]
	},
    edit: {
		enable: true,
		editNameSelectAll: false,
		showRemoveBtn: true,
		showRenameBtn: true,
		removeTitle: "删除",
		renameTitle: "修改"
	},
	callback: {
		beforeDrag: function (treeId, treeNodes) {
			return false;
		},
        onAsyncSuccess:function(event, treeId, treeNode, msg){            
            var ztree = $.fn.zTree.getZTreeObj(treeId);
           // var roots = ztree.getNodesByParam("ParentId", 0);
            var roots = ztree.getNodes();
            if(roots.length>0){
                ztree.expandNode(roots[0],true);
            }
            //$.fn.zTree.getZTreeObj(treeId).expandAll(true);
        },
        beforeRename: function(treeId, treeNode, newName, isCancel){
            $.get("/SystemManage/weixin/Response/KeywordRuleTree.aspx?op=UpdateKeywordRule", {RuleTitle:newName, ParentId:treeNode.ParentId, Id:treeNode.Id, temp:new Date().valueOf()}, function(data){
                
                var obj=$.parseJSON(data);
                treeNode.RuleTitle = obj.RuleTitle;
                $.fn.zTree.getZTreeObj(treeId).updateNode(treeNode);
                alertMsg.correct("操作成功");
            });
            return true;
        },
        beforeRemove:function(treeId, treeNode){
            alertMsg.confirm("请确认删除当前菜单项", {
                okCall: function() {
                    $.get("/SystemManage/weixin/Response/KeywordRuleTree.aspx?op=RemoveKeywordRule", {Id:treeNode.Id, temp:new Date().valueOf()}, function(data){
                        $.fn.zTree.getZTreeObj(treeId).removeChildNodes(treeNode);
                        $.fn.zTree.getZTreeObj(treeId).removeNode(treeNode);
                        alertMsg.correct("操作成功");
                    }); 
                }
            });
            return false;
        },
        onClick:function(event, treeId, treeNode, clickFlag){
            $("#Id",navTab.getCurrentPanel()).val(treeNode.Id);
            $("#keywords",navTab.getCurrentPanel()).val(treeNode.RequestKeyword);
            $("#matfield",navTab.getCurrentPanel()).val(treeNode.ResponseMaterialId);
            $("#matfield_ttl", navTab.getCurrentPanel()).val("");
            var matchVal = (treeNode.FullMatch=="1"?true:false);
            $("#fullmatch",navTab.getCurrentPanel()).attr("checked",matchVal);
            $.get("/SystemManage/weixin/Material/LoadMaterial.aspx", {uid:treeNode.ResponseMaterialId, temp:new Date().valueOf()}, function(data){
                try{
                    var obj=$.parseJSON(data);   
                    $("#matfield_ttl", navTab.getCurrentPanel()).val(obj.Title);
                }catch(e){}
            }); 
        }
	}
}
'/>
</div>
<div class="formBar">
	    <ul>
			<li>
	        <div class="buttonActive"><div class="buttonContent"><button onclick="addRule('menu_tree')" type="button">添加规则</button></div></div>
            </li>
		</ul>
</div>
<script type="text/javascript">
    function addRule(treeId, parentNode) {
        var pid = 0;
        if (parentNode) {
            pid = parentNode.Id;
        }
        $.ajax({
            url: '/SystemManage/weixin/Response/KeywordRuleTree.aspx?op=AddKeywordRule',
            data: { RuleTitle: "新的规则", ParentId: pid, temp: new Date().valueOf() },
            type: 'POST',
            dataType: 'json',
            cache: false,
            success: function (data) {
                var zTree = $.fn.zTree.getZTreeObj(treeId);
                if (parentNode) {
                    zTree.addNodes(parentNode, data);
                } else {
                    zTree.addNodes(null, data);
                }
            }
        });

    }

    function addHoverDom(treeId, treeNode) {
        var sObj = $("#" + treeNode.tId + "_span");
        if (treeNode.editNameFlag || $("#addBtn_" + treeNode.tId).length > 0) return;
        var addStr = "<span class='button add' id='addBtn_" + treeNode.tId
				+ "' title='增加子规则' onfocus='this.blur();'></span>";
        sObj.after(addStr);
        var btn = $("#addBtn_" + treeNode.tId);
        if (btn) btn.bind("click", function () {
            addRule(treeId, treeNode);
            return false;
        });
    };
    function removeHoverDom(treeId, treeNode) {
        $("#addBtn_" + treeNode.tId).unbind().remove();
    };

    function saveKeywordDetail() {
        var RequestKeyword = $("#keywords", navTab.getCurrentPanel()).val();
        var ResponseMaterialId = $("#matfield", navTab.getCurrentPanel()).val();
        
        if (RequestKeyword == '' || ResponseMaterialId == '') {
            alertMsg.error("部分信息不能为空");
            return;
        }
        $.ajax({
            url: '/SystemManage/weixin/Response/KeywordRuleTree.aspx?op=SaveKeywordRuleDetail',
            data: { 
                Id: $("#Id", navTab.getCurrentPanel()).val(),
                RequestKeyword:RequestKeyword ,
                ResponseMaterialId: ResponseMaterialId,
                FullMatch: ($("#fullmatch", navTab.getCurrentPanel()).attr("checked") == true?"1":"0"),
                temp: new Date().valueOf() 
                },
            type: 'POST',
            dataType: 'json',
            cache: false,
            success: function (data) {
                var treeObj = $.fn.zTree.getZTreeObj('menu_tree');
                var nodes = treeObj.getNodesByParam("Id", data.Id, null);
                if (nodes.length == 1) {
                    nodes[0].RequestKeyword = data.RequestKeyword;
                    nodes[0].ResponseMaterialId = data.ResponseMaterialId;
                    nodes[0].FullMatch = data.FullMatch;
                }
                alertMsg.correct("操作成功");
            }
        });
    }
</script>

 
</div>
      

	</div>
	
<div class="unitBox" style="margin-left:360px;">
	<div class="pageHeader" style="border:1px #B8D0D6 solid">
	<div class="searchBar">
		<table class="searchContent">
			<tr>
				<td><h3>详细设置</h3>
				</td>

			</tr>
		</table>
	</div>
</div>	

<div class="pageContent" style="border:1px #B8D0D6 solid;"  layoutH="70">

<div class="pageFormContent" layoutH="128">     

        <dl class="nowrap">
            <dt>关键词</dt>
            <dd><textarea id="keywords" cols="75" rows="2" class="required" ></textarea></dd>
        </dl>
         <dt>&nbsp;</dt>
            <dd>必须使用半角逗号分隔多个关键词</dd>
    
        <dl class="nowrap">
            <dt>全匹配：</dt>
            <dd>
                <input id="fullmatch" type="checkbox" />
            </dd>
        </dl>
        
        <dl class="nowrap">
            <dt>选择素材：</dt>
            <dd>
                <uc1:SetMaterialControl ID="SetMaterialControl1" runat="server" />
            </dd>
        </dl>
				<input id="Id" type="hidden"/>
        <dl class="nowrap">
            <dt>注意：</dt>
            <dd>（1、关键词设置请避免出现交集，以确保回复正确的信息。）<br />（2、全匹配：当整个词语和设置的关键词一致时，才判断为匹配。）</dd>
        </dl>
</div>


<div class="formBar">
	    <ul>
			<li>
	        <div class="buttonActive"><div class="buttonContent"><button onclick="saveKeywordDetail();" type="button">保存</button></div></div>
            </li>
		</ul>
</div>
</div>

</div>
	
</div>